import { BasicTableProps, FormProps } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { useI18n } from '/@/hooks/web/useI18n';
import { patientApi } from '/@/api/console/patient';
import { choiceFieldApi } from '/@/api/sys/choice';
const { t } = useI18n();

function getTableColumns(): BasicColumn[] {
  return [
    {
      title: t('views.patient.code'),
      dataIndex: 'code',
      fixed: 'left',
      width: 75,
    },
    {
      title: t('views.patient.name'),
      edit: true,
      dataIndex: 'name',
      width: 75,
    },
    {
      title: t('views.patient.age'),
      dataIndex: 'age',
      edit: true,
      width: 75,
    },
    {
      title: t('views.patient.gender'),
      dataIndex: ['gender', 'name'],
      // customRender: ({ text }) => text.name,
      edit: true,
      editComponent: 'ApiSelect',
      editComponentProps: {
        api: () => choiceFieldApi.list('console', 'patient', 'gender'),
        labelField: 'name',
        valueField: 'value',
      },
      width: 75,
    },
    {
      title: t('views.patient.phone'),
      dataIndex: 'phone',
      edit: true,
      width: 75,
    },
    {
      title: t('views.patient.clinical_diagnosis'),
      edit: true,
      dataIndex: 'clinical_diagnosis',
      ellipsis: false,
      width: 150,
    },
    {
      title: t('views.patient.medication_history'),
      edit: true,
      dataIndex: 'medication_history',
      ellipsis: false,
      width: 150,
    },
  ];
}

function getTableFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 80,
    actionColOptions: {
      span: 4,
    },
    schemas: [
      {
        label: t('common.queryText'),
        field: 'query',
        component: 'Input',
        colProps: {
          span: 6,
        },
      },
    ],
  };
}
export function getTableProps(): BasicTableProps {
  return {
    title: '受检者',
    rowKey: 'id',
    showIndexColumn: false,
    columns: getTableColumns(),
    api: (params) => patientApi.list(params),
    showTableSetting: true,
    tableSetting: { fullScreen: true },
    useSearchForm: true,
    formConfig: getTableFormConfig(),
    actionColumn: {
      width: 60,
      title: t('common.optText'),
      dataIndex: 'action',
      slots: { customRender: 'action' },
    },
  };
}
